package com.czy.owner.adapter;


import android.content.Context;
import android.graphics.Paint;
import android.view.ViewGroup;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.PackageCardProjectModel;
import com.czy.owner.utils.TimeUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 * Created by wangyang on 2017/4/14 0014.
 */

public class PackageCardProjectAdapter extends RecyclerArrayAdapter<PackageCardProjectModel> {
    private Context ctx;

    public PackageCardProjectAdapter(Context context) {
        super(context);
        this.ctx = context;

    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new PackageCardProjectViewHolder(parent, ctx);
    }

    class PackageCardProjectViewHolder extends BaseViewHolder<PackageCardProjectModel> {
        private TextView tv_package_card_name;
        private TextView tv_use_time;
        private TextView tv_old_price;
        private TextView tv_new_price;
        private Context ctx;


        public PackageCardProjectViewHolder(ViewGroup parent, Context ctx) {
            super(parent, R.layout.item_store_package_card_project);
            tv_package_card_name = $(R.id.tv_package_card_name);
            tv_use_time = $(R.id.tv_use_time);
            tv_old_price = $(R.id.tv_old_price);
            tv_new_price = $(R.id.tv_new_price);
            this.ctx = ctx;
        }

        @Override
        public void setData(final PackageCardProjectModel model) {

            int validityType = model.getValidityType();//0>>>永久有效;1>>>固定时长;2>>>固定时间
            int fixTimeType = model.getFixTimeType();//0>>>>>月;1>>>>年
            long startTime = model.getStartTime();
            long endTime = model.getEndTime();

            if (validityType == 0) {
                tv_use_time.setText("永久有效");
            } else if (validityType == 1) {
                if (fixTimeType == 0) {
                    tv_use_time.setText(model.getFixTimeValue() + "个月有效");
                } else if (fixTimeType == 1) {
                    tv_use_time.setText(model.getFixTimeValue() + "年有效");
                }
            } else if (validityType == 2) {
                tv_use_time.setText(TimeUtils.formatTimeDifference4(startTime) + "-" + TimeUtils.formatTimeDifference4(endTime) + "有效");
            }
            tv_package_card_name.setText(model.getPackageName());
            tv_old_price.setText("原价￥" + String.format("%.2f", model.getOriginalPrice()));
            tv_new_price.setText(String.format("%.2f", model.getPrice()));
            tv_old_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);  // 设置中划线并加清晰

        }
    }
}
